<?php
if(!empty($_POST)){
	require('connect.php');
	$checkTanks = $_POST['checkTanks'];
	$userId = $_POST['userId'];

	if($checkTanks == '1'){
		$query = "SELECT TankID, 
		Product,
		Qty
		where UserID = '$userId'";
		$rows = sqlsrv_query( $conn, $query);
		$datos = array();
		while($row = sqlsrv_fetch_array( $rows, SQLSRV_FETCH_ASSOC) ) {		
			$datos[]= array('TankID'=>$row['TankID'],'Product'=>$row['Product'],,'Qty'=>$row['Qty']);
		}
		echo json_encode($datos);
	} else {
		$userId = $_POST['userId'];
		$tanks = json_decode($_POST['tanks']);
		foreach($tanks as $tank) {
			$sql = "INSERT INTO TanksByUser (UserID,TankID,Product,Qty) VALUES (?, ?, ?, ?)";
			$params = array($userId,$tank->TankId,$tank->Product,$tank->Qty);
			sqlsrv_query( $conn, $sql, $params);
		}
	}
	sqlsrv_close($conn);
}
?>